package com.ruoyi.project.travel.service.impl;

import com.ruoyi.project.tool.upload.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.project.travel.mapper.ScenicMapper;
import com.ruoyi.project.travel.domain.Scenic;
import com.ruoyi.project.travel.service.IScenicService;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * 景区 Service业务层处理
 * 
 * @author HYD
 * @date 2020-06-14
 */
@Service
public class ScenicServiceImpl extends ServiceImpl<ScenicMapper, Scenic> implements IScenicService {

    @Autowired
    private ScenicMapper scenicMapper;


    @Autowired
    private UploadService uploadService;


    /**
     * 删除图片
     * @param scenicId
     * @param type 0：主图 1：其他图片
     * @param delImg 删除图片的路径
     * @param photoPath 除了删除图片剩下的路径
     * @return
     */
    @Override
    @Transactional
    public int delImg(Long scenicId,int type,String delImg,String photoPath){
        uploadService.delImage(delImg);
        Scenic scenic = new Scenic();
        scenic.setId(scenicId);
        if(type == 0){
            scenic.setImages("");
        }else{
            scenic.setOtherImg(photoPath);
        }
        scenic.setUpdateTime(new Date());
        return scenicMapper.updateById(scenic);
    }
}
